<template>
  <view class="container">
    <view class="header">
      <text class="title">数据分析</text>
      <button class="back-btn" @click="goBack">返回首页</button>
    </view>
    
    <view class="section">
      <view class="section-header">
        <text class="section-title">平台分布</text>
        <view class="section-icon">📱</view>
      </view>
      <view class="platform-chart">
        <view 
          v-for="(platform, index) in platformData" 
          :key="index" 
          class="platform-bar"
          :style="{ width: platform.value + '%', backgroundColor: platform.color }"
        >
          <text class="platform-name">{{ platform.name }}</text>
          <text class="platform-value">{{ platform.value }}%</text>
        </view>
      </view>
    </view>
    
    <view class="section">
      <view class="section-header">
        <text class="section-title">年龄分布</text>
        <view class="section-icon">👥</view>
      </view>
      <view class="age-chart">
        <view 
          v-for="(age, index) in ageData" 
          :key="index" 
          class="age-item"
        >
          <view class="age-bar-container">
            <view 
              class="age-bar" 
              :style="{ width: age.value + '%', backgroundColor: age.color }"
            ></view>
          </view>
          <view class="age-info">
            <text class="age-name">{{ age.name }}</text>
            <text class="age-value">{{ age.value }}%</text>
          </view>
        </view>
      </view>
    </view>
    
    <view class="section">
      <view class="section-header">
        <text class="section-title">地区兴趣分布</text>
        <view class="section-icon">🌏</view>
      </view>
      <view class="region-list">
        <view v-for="region in regionData" :key="region.name" class="region-item">
          <text class="region-name">{{ region.name }}</text>
          <view class="progress-container">
            <view class="progress-bar" :style="{ width: region.value + '%' }"></view>
          </view>
          <text class="region-value">{{ region.value }}%</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'

const platformData = ref([
  { name: '微博', value: 45, color: '#3498db' },
  { name: '朋友圈', value: 30, color: '#2ecc71' },
  { name: '抖音', value: 25, color: '#e74c3c' }
])

const ageData = ref([
  { name: '18-25岁', value: 35, color: '#e74c3c' },
  { name: '26-35岁', value: 40, color: '#3498db' },
  { name: '36-45岁', value: 18, color: '#2ecc71' },
  { name: '45岁以上', value: 7, color: '#f39c12' }
])

const regionData = ref([
  { name: '华东地区', value: 32 },
  { name: '华南地区', value: 25 },
  { name: '华北地区', value: 18 },
  { name: '西南地区', value: 15 },
  { name: '东北地区', value: 10 }
])

const goBack = () => {
  uni.switchTab({ url: '/pages/index/index' })
}
</script>

<style scoped>
.container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 15px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.title {
  font-size: 18px;
  font-weight: bold;
}

.back-btn {
  background: #007aff;
  color: white;
  border-radius: 15px;
  padding: 8px 16px;
  font-size: 14px;
  border: none;
}

.section {
  background: white;
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  border-left: 4px solid #007aff;
  padding-left: 10px;
}

.section-icon {
  font-size: 20px;
}

.platform-chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.platform-bar {
  height: 40px;
  border-radius: 20px;
  padding: 0 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  font-weight: bold;
  transition: all 0.3s;
  animation: growBar 1s ease-out forwards;
}

@keyframes growBar {
  from { width: 0; }
}

.platform-name {
  font-size: 14px;
}

.platform-value {
  font-size: 16px;
}

.age-chart {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.age-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.age-bar-container {
  height: 10px;
  background: #ecf0f1;
  border-radius: 5px;
  overflow: hidden;
}

.age-bar {
  height: 100%;
  border-radius: 5px;
  animation: growBar 1s ease-out forwards;
}

.age-info {
  display: flex;
  justify-content: space-between;
}

.age-name {
  font-size: 14px;
  color: #333;
}

.age-value {
  font-size: 14px;
  color: #007aff;
  font-weight: bold;
}

.region-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.region-item {
  display: flex;
  align-items: center;
}

.region-name {
  width: 80px;
  font-size: 14px;
}

.progress-container {
  flex: 1;
  height: 10px;
  background: #ecf0f1;
  border-radius: 5px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #6a11cb, #2575fc);
  border-radius: 5px;
  animation: growBar 1s ease-out forwards;
}

.region-value {
  width: 40px;
  text-align: right;
  font-size: 14px;
  color: #007aff;
  font-weight: bold;
}
</style>